/**
 * 功能：控制衔接中列中按钮显示
 * 权限：监狱用户
 */
function autoOperateControl(e) {
    var record = e.value;
    var s = "";
    if (record != "" && record != null) {
        var arr = record.split("@");
        var death = arr[2];
        if (death == "1") {
        } else {
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="dxjTabs()">&nbsp;&nbsp;发起衔接&nbsp;&nbsp;</a>&nbsp';
        }
    } else {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="dxjTabs()">&nbsp;&nbsp;发起衔接&nbsp;&nbsp;</a>&nbsp';
    }
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="rowdblclick()">&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
    return s;
}

//信息补录操作按钮控制
function autoOperateXxbl(e) {
    var s = "";
    s += '&nbsp;<a class="mini-button mini-button-primary"  onclick="xxblTabs()"  >&nbsp;&nbsp;信息补录&nbsp;&nbsp;</a>&nbsp'
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="rowdblclick()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
    return s;
}

/**
 * 信息补录tabs页面
 */
function xxblTabs() {
    var row = grid.getSelected();//获取列表行数据
    if (row.priNum) {
        $.ajax({
            type: "get",
            url: "/azbj/transfer/fqqy/getTransferRecord?1=1&priNums=" + row.priNum,
            dataType: "json",
            success: function (data) {
                if (data.code == '1') {
                    commonEdit("/azbj/yazgl/xxbl/tabs?1=1&priNum=" + row.priNum + "&pristopold=" + row.cjDate, "信息补录", {
                        action: "edit",
                        priNum: row.priNum
                    }, "50%", "92%", true, true, true, callback);
                } else {
                    mini.alert("此服刑人员正在数据迁移,请完成迁移后再进行此操作!");
                }
            }
        });
    }

    function callback() {
        grid.reload();
    }
}

/**
 * 衔接补录编辑页面
 */
function xxblTabsEdit() {
    var row = grid.getSelected();//获取列表行数据
    commonEdit("/azbj/yazgl/xxbl/tabsEdit?1=1&priNum=" + row.priNum + "&pristopold=" + row.cjDate, "信息补录", {
        action: "edit",
        priNum: row.priNum
    }, "50%", "92%", true, true, true, callback);

    function callback() {
        grid.reload();
    }
}

/**
 * 信息补录-出监评估
 */
function bulu() {
    var row = grid.getSelected();//获取列表行数据
    commonEdit("/azbj/yazgl/xxbl/cjpg?1=1&id=" + row.id + "&priNum=" + row.priNum + "&taskId=" + row.taskId + "&sanwu=" + row.sanwu +
        "&sanjia=" + row.sanjia + "&aftype=" + row.aftype + "&pinggu=" + row.pinggu + "&nativepro=" + row.nativeproName + "&nativecity=" + row.nativecityName
        + "&nativecou=" + row.nativecouName + "&nativevill=" + row.nativevillName, "信息补录", {
        action: "edit",
        sanwu: row.sanwu,
        sanjia: row.sanjia,
        aftype: row.aftype,
        canji: row.pinggu,
    }, "50%", "90%", true, true, true, callback);

    function callback() {
        grid.reload();
    }
}

/**
 * 待衔接-tabs页面
 */
function dxjTabs() {
    var row = grid.getSelected();//获取列表行数据
    if (row.priNum) {
        $.ajax({
            type: "get",
            url: "/azbj/transfer/fqqy/getTransferRecord?1=1&priNums=" + row.priNum,
            dataType: "json",
            success: function (data) {
                if (data.code == '1') {
                    if (row.pinggu && row.pinggu != '无') {
                        commonEdit("/azbj/yazgl/dxj/tabs?1=1&id=" + row.id + "&priNum=" + row.priNum + "&pName=" + row.pname + "&pinggu=" + row.pinggu, "待衔接", {
                            action: "edit",
                            priNum: row.priNum
                        }, "55%", "60%", true, true, true, callback);
                    } else {
                        mini.alert("信息没有补录完整!");
                    }
                } else {
                    mini.alert("此服刑人员正在数据迁移,请完成迁移后再进行此操作!");
                }
            }
        });
    }

    function callback() {
        grid.reload();
    }
}

/**
 * 待衔接-回执_监狱
 */
function hz() {
    var row = grid.getSelected();//获取列表行数据
    commonEdit("/azbj/yazgl/xj/hz?priNum=" + row.priNum, "回执", null, 666, 468, true, false, true, callback);

    function callback() {
        grid.reload();
    }
}

//导出衔接信息函
function exportfile1() {
    var row = grid.getSelected();
    if (row) {
        window.location.href = encodeURI("/azbj/azbjgl/doc/export?priNum=" + row.priNum + "&type=3");
    } else {
        mini.alert("请选中一条记录");
    }
}

//衔接成功导出衔接信息函和衔接回执单
function exportfiles() {
    var row = grid.getSelected();
    if (row) {
        mini.open({
            url: "/azbj/azbjgl/doc/exportfiles?priNum=" + row.priNum + "&type=xj",
            title: "文件导出", width: '380px', height: '180px',
            allowResize: false,
            onload: function () {
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    } else {
        alert("请至少选择一条数据！");
    }
}

/**
 * 待衔接-回执_司法所
 */
function hz_sfs() {
    var row = grid.getSelected();
    commonEdit("/azbj/yazgl/xj/hzsfs?priNum=" + row.priNum, "回执", null, 666, 468, true, false, true, callback);
    function callback() {
        grid.reload();
    }
}

/**
 * 待衔接-完成衔接
 */
function completely() {
    var row = grid.getSelected();//获取列表行数据
    var secondstate = row.secondstate.split("?")[2];
    commonEdit("/azbj/yazgl/xj/completely?priNum=" + row.priNum + "&secstatexj=" + secondstate + "&id=" + row.xjxxid + "&pdanwei="+row.pdanwei, "司法所衔接信息", "", "50%", "65%", true, true, true, callback);
    function callback() {
        grid.reload();
    }
}

//户籍完整
function selectHjwz(url1) {
    var url = url1 + "&type=1";
    grid.setUrl(url);
    grid.reload();
}

//查不清户籍
function selectNoHj(url1) {
    var url = url1 + "&type=2";
    grid.setUrl(url);
    grid.reload();
}

//有未成年子女成员
function juvenileInfo(url1) {
    var url = url1 + "&type=3";
    grid.setUrl(url);
    grid.reload();
}

//查询所有信息
function allInfo(url1) {
    grid.setUrl(url1);
    grid.reload();
}

//无照片指纹
function nomutiInfo(url1) {
    var url = url1 + "&type=4";
    grid.setUrl(url);
    grid.reload();
}

//今日释放
function jinRiShiFang(url1) {
    var url = url1 + "&type=5";
    grid.setUrl(url);
    grid.reload();
}

//未录入狱中表现
function weiLuRuYuZhongBiaoXian(url1) {
    var url = url1 + "&type=6";
    grid.setUrl(url);
    grid.reload();
}

// 未录入危险性评估
function noPingGu(url1) {
    var url = url1 + "&type=7";
    grid.setUrl(url);
    grid.reload();
}

// 帮教对象类别
function bjdxlb(url1, type) {
    var url = url1 + "&type=" + type;
    grid.setUrl(url);
    grid.reload();
}

//基本查询
function shaiSelect() {
    var val = mini.get("shaixuan").getValue();
    if (val == "0") {////查询所有信息
        allInfo(url);
    } else if (val == "01") {  //户籍完整
        selectHjwz(url);
    } else if (val == "2") {////查不清户籍
        selectNoHj(url);
    } else if (val == "3") {//有未成年子女成员
        juvenileInfo(url);
    } else if (val == "4") {//无照片指纹
        nomutiInfo(url);
    } else if (val == "5") {////今日释放
        jinRiShiFang(url);
    } else if (val == "6") {//未录入狱中表现
        weiLuRuYuZhongBiaoXian(url);
    } else if (val == "7") { // 未录入危险性评估
        noPingGu(url);
    } else if (val == "8") { // 重点帮教对象
        bjdxlb(url, 8);
    } else if (val == "9") { // 一般帮教对象
        bjdxlb(url, 9);
    }
}

function onBluztRenderer(e) {
    var row1 = e.row;
    if (row1.blzt == 0 || row1.blzt == "无") {
        return "否";
    } else {
        return "是";
    }
}

function moveToAnZhi() {
    var row = grid.getSelected();//获取列表行数据
    if (row.flag == "1") {
        mini.alert("已转到安置帮教");
    } else {
        mini.confirm("确定要转到安置帮教?","确定?",function(action){
            if (action == 'ok'){
                $.ajax({
                    type: "post",
                    url: "/azbj/yazgl/xj/move/anzhi?1=1&priNum=" + row.priNum,
                    dataType: "json",
                    success: function (data) {
                        if (data.code == '1') {
                            mini.alert("安置成功！");
                            grid.reload();
                        } else if (data.code == 5599) {
                            mini.alert(data.message);
                        } else {
                            mini.alert("安置失败！");
                            grid.reload();
                        }
                    }
                });
            }else{
                return;
            }
        })
    }
}

/**
 * 列表双击事件
 * @param e
 */
function rowdblclick(e) {
    //var data = e.record;
    var row = grid.getSelected();
    mini.open({
        // targetWindow: window,
        url: "/azbj/baseInfo/hjqc/toViewTabs/view?priNum=" + row.priNum,
        title: "查看",
        width: "65%",
        height: "80%",
        allowDrag: true,
        allowResize: false,
        showCloseButton: true,
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

function onPingGuRenderer(e) {
    if (e.value != null && e.value != '' && e.value != '无') {
        return "是";
    } else {
        return "否";
    }
}

//衔接失败
function onHjqrSuoActionRenderer(e) {
    var record = e.value;
    var arr = record.split("?");
    var state = arr[0];
    var level = arr[1];
    var state_xj = arr[2];
    var s = "";
    if (state == "0" && level == "01") {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="toReportJyj()"  >&nbsp;&nbsp;上报监狱局&nbsp;&nbsp;</a>&nbsp';
    } else if (state == "0" && level == "05") {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="toReportJyj()"  >&nbsp;&nbsp;上报社矫管理局&nbsp;&nbsp;</a>&nbsp';
    } else if (state == "0" && level == "02") {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="toReportJyj()"  >&nbsp;&nbsp;上报监管总队&nbsp;&nbsp;</a>&nbsp';
    } else if (state == "1" && (level == "09" || level == "4" || level == "15")) {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="toReportJyj()"  >&nbsp;&nbsp;上报司法厅&nbsp;&nbsp;</a>&nbsp';
    } else if ((state == "2" || state == "6") && level == "06") {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="toReportJyj()"  >&nbsp;&nbsp;处理&nbsp;&nbsp;</a>&nbsp';
    } else if ((state == "3" || state == "5" || state == "7") && (level == "01" || level == "05" || level == "02") && state_xj == "-1") {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="toAgainXj()"  >&nbsp;&nbsp;重新发起衔接&nbsp;&nbsp;</a>&nbsp';
    }
    s += '&nbsp;<a class="mini-button mini-button-success"  onclick="toReportJyjView()"  >&nbsp;&nbsp;详情&nbsp;&nbsp;</a>&nbsp'
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="rowdblclick()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
    return s;
}

//未衔接
function onWxjSuoActionRenderer(e) {
    var record = e.value;
    var arr = record.split("@");
    var flag = arr[0];
    var level = arr[1];
    var s = "";
    if (flag == "0" && level == '03') {
        s += '&nbsp;<a class="mini-button mini-button-warning" onclick="moveToAnZhi()"  >&nbsp;&nbsp;转到安置帮教&nbsp;&nbsp;</a>&nbsp';
    }
    s += '&nbsp;<a class="mini-button mini-button-info" onclick="rowdblclick()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp'
    return s;
}

//衔接中
function onXjActionRenderer(e) {
    var record = e.value;
    var arr = record.split("@");
    var flag = arr[0];
    var level = arr[1];
    var receiveType = arr[2];
    var localCode = arr[3];
    var s = "";
    if (flag == "1" && level == '03') {
        if (receiveType == "0") { // 条件,司法所未进行签收时展示签收按钮,签收后展示
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="sfsqs()"  >&nbsp;&nbsp;签收&nbsp;&nbsp;</a>&nbsp';
        } else if (receiveType == "1") { // 司法所签收后,展示回执,完成衔接操作按钮
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;回执&nbsp;&nbsp;</a>&nbsp';
            s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="completely()"  >&nbsp;&nbsp;完成衔接&nbsp;&nbsp;</a>&nbsp';
        } else{
            if (undefined != receiveType) {
                s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz_sfs()"  >&nbsp;&nbsp;回执&nbsp;&nbsp;</a>&nbsp';
                if(localCode == '140000') {
                    s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="completely()"  >&nbsp;&nbsp;确认衔接&nbsp;&nbsp;</a>&nbsp';
                } else {
                    s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="completely()"  >&nbsp;&nbsp;完成衔接&nbsp;&nbsp;</a>&nbsp';
                }
            }
        }
    } else if ((flag == "1" || flag == "0") && level == '01') {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz()">&nbsp;&nbsp;回执&nbsp;&nbsp;</a>&nbsp';
    } else if ((flag == "1" || flag == "0") && level == '02') {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz()">&nbsp;&nbsp;回执&nbsp;&nbsp;</a>&nbsp';
    } else if ((flag == "1" || flag == "0") && level == '05') {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="hz()">&nbsp;&nbsp;回执&nbsp;&nbsp;</a>&nbsp';
    }
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="rowdblclick()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    s += '&nbsp;<a class="mini-button mini-button-success"  onclick="exportfile1()"  >&nbsp;&nbsp;导出&nbsp;&nbsp;</a>&nbsp';
    return s;
}

/**
 * 上报监狱局
 */
function toReportJyj() {
    var row = grid.getSelected();//获取列表行数据
    mini.open({
        url: "/azbj/ysfryxj/xjsb/report?priNum=" + row.priNum + "&secondstate=" + row.secstate,
        title: "二次衔接上报", width: 600, height: 650,
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

function toReportJyjView() {
    var row = grid.getSelected();//获取列表行数据
    mini.open({
        url: "/azbj/ysfryxj/xjsb/report/view?priNum=" + row.priNum,
        title: "二次衔接上报查看", width: 600, height: 650,
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

/**
 * 再次发起发起衔接
 */
function toAgainXj() {
    var row = grid.getSelected();//获取列表行数据
    mini.open({
        url: "/azbj/ysfryxj/xjsb/againxj?priNum=" + row.priNum + "&secondstate=" + row.secstate,
        title: "重新发起衔接", width: 800, height: 600,
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}

//附件补录：主要是监狱用户补录出监评估和刑满释放通知书附件
function addfiles() {
    var row = grid.getSelected();
    if (row) {
        mini.open({
            url: "/azbj/azbjgl/doc/addfiles?priNum=" + row.priNum + "&fileid=" + row.xjxxid,
            title: "附件补录", width: '480px', height: '180px',
            allowResize: false,
            onload: function () {
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    } else {
        alert("请至少选择一条数据！");
    }
}

/**
 * 湖南看守所个性化 - 签收
 */
function sfsqs() {
    var row = grid.getSelected();
    if (row) {
        var url = "/azbj/verification/signFor";
        mini.confirm("确认签收此服刑人员？",
            "确定？",
            function (action) {
                if (action == "ok") {
                    $.ajax({
                        url: url,
                        type: 'POST',
                        cache: false,
                        async: false,
                        data: {priNum: row.priNum, type: "3"},
                        success: function (data) {
                            if(data.code == '1') {
                                mini.alert("签收成功!");
                            } else if (data.code == 5599) {
                                mini.alert(data.message);
                            } else {
                                mini.alert("签收失败!");
                            }
                            grid.reload();
                        }, error: function () {
                            mini.alert("操作失败!");
                        }
                    });
                }
            });
    } else {
        mini.alert("请选中一条记录");
    }
}